package com.chuantou.yuba.api.request;

import java.util.Map;

import com.android.volley.Request;
import com.android.volley.Response.ErrorListener;
import com.chuantou.yuba.api.ApiContext;
import com.chuantou.yuba.api.serializer.NewsDetailSerializer;
import com.chuantou.yuba.api.to.BaseNewsTypeTO;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public abstract class BaseGsonRequest<T> extends Request<T> {

	protected ApiContext mApiContext;

	protected Map<String, String> mParams;

	public BaseGsonRequest(int method, String url, Map<String, String> params, ErrorListener listener) {
		super(method, url, listener);
		this.mParams = params;
	}

	protected Gson createGson() {
		GsonBuilder gsonb = new GsonBuilder();
		gsonb.serializeNulls();
		gsonb.registerTypeAdapter(BaseNewsTypeTO.class, new NewsDetailSerializer());
		Gson gson = gsonb.create();
		return gson;
	}

	public void setApiContext(ApiContext context) {
		this.mApiContext = context;
	}

	@Override
	public Map<String, String> getParams() {
		return mParams;
	}
}
